import BaseHTTPServer
import logging
import threading

class HealthRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header('Content-Type', 'text/plain')
        self.end_headers()
        self.wfile.write('alive')

    def log_request(*args, **kwargs):
        pass

    def log_error(*args, **kwargs):
        pass

    def log_message(*args, **kwargs):
        pass

def serve_health():
    addr = ('127.0.0.1', 8001)
    httpd = BaseHTTPServer.HTTPServer(addr, HealthRequestHandler)
    logging.getLogger('health').info('Serving health info on localhost:8001')
    httpd.serve_forever()

def serve_health_thread():
    t = threading.Thread(target=serve_health)
    t.setDaemon(True)
    t.start()
